package com.suao.web.controller.fruits;

import com.suao.common.annotation.Log;
import com.suao.common.core.controller.BaseController;
import com.suao.common.core.domain.AjaxResult;
import com.suao.common.core.page.TableDataInfo;
import com.suao.common.enums.BusinessType;
import com.suao.common.utils.poi.ExcelUtil;
import com.suao.fruits.domain.FruitsSalesInfo;
import com.suao.fruits.service.IFruitsSalesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 水果销售流水Controller
 *
 * @author tyz
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/fruits/fruitsSalesInfo")
public class FruitsSalesInfoController extends BaseController
{
    @Autowired
    private IFruitsSalesInfoService fruitsSalesInfoService;

    /**
     * 查询水果销售流水列表
     */
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(FruitsSalesInfo fruitsSalesInfo)
    {
        startPage();
        List<FruitsSalesInfo> list = fruitsSalesInfoService.selectFruitsSalesInfoList(fruitsSalesInfo);
        return getDataTable(list);
    }
    
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(FruitsSalesInfo fruitsSalesInfo)
    {
        List<FruitsSalesInfo> list = fruitsSalesInfoService.selectFruitsSalesInfoList(fruitsSalesInfo);
        return getDataTable(list);
    }

    /**
     * 导出水果销售流水列表
     */
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:export')")
    @Log(title = "水果销售流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FruitsSalesInfo fruitsSalesInfo)
    {
        List<FruitsSalesInfo> list = fruitsSalesInfoService.selectFruitsSalesInfoList(fruitsSalesInfo);
        ExcelUtil<FruitsSalesInfo> util = new ExcelUtil<FruitsSalesInfo>(FruitsSalesInfo.class);
        util.exportExcel(response, list, "水果销售流水数据");
    }

    /**
     * 获取水果销售流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fruitsSalesInfoService.selectFruitsSalesInfoById(id));
    }

    /**
     * 新增水果销售流水
     */
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:add')")
    @Log(title = "水果销售流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FruitsSalesInfo fruitsSalesInfo)
    {
        return toAjax(fruitsSalesInfoService.insertFruitsSalesInfo(fruitsSalesInfo));
    }

    /**
     * 修改水果销售流水
     */
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:edit')")
    @Log(title = "水果销售流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FruitsSalesInfo fruitsSalesInfo)
    {
        return toAjax(fruitsSalesInfoService.updateFruitsSalesInfo(fruitsSalesInfo));
    }

    /**
     * 删除水果销售流水
     */
    @PreAuthorize("@ss.hasPermi('fruits:fruitsSalesInfo:remove')")
    @Log(title = "水果销售流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fruitsSalesInfoService.deleteFruitsSalesInfoByIds(ids));
    }
}
